package com.stoken.web.control;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.stoken.domain.MemberLeaveType;
import com.stoken.service.MemberLeaveTypeService;
import com.symbio.commons.Compositor;
import com.symbio.commons.Compositor.CompositorType;
import com.symbio.commons.Page;
import com.symbio.utils.WebUtils;

/**
 * 会员留言类型管理
 * @author Fred
 *
 */
@Controller
@RequestMapping("/leaveType")
public class MemberLeaveTypeControl {
	
	@Autowired
	private MemberLeaveTypeService mbLeaveTypeService;
	
	/**
	 * 留言类型列表
	 * @return
	 */
	@RequestMapping("/backstage/loadTypeList")
	public String loadNoticeList(){		
		return "/backstage/leaveMessage/leaveTypeList";
	}
	
	/**
	 * 增加留言类型
	 */
	@RequestMapping(value="/backstage/leaveTypeAdd",method=RequestMethod.POST)
	public String addUser(MemberLeaveType leaveType,HttpServletRequest request,ModelMap modeMape){	
		
		mbLeaveTypeService.save(leaveType);			
		
		return "/backstage/leaveMessage/leaveTypeList";
	}
	
	/**
	 * 查询留言类型数据
	 * @param request
	 * @param modeMape
	 * @return
	 */
	@RequestMapping("/backstage/leaveTypeData")
	public String leaveTypeData(HttpServletRequest request,ModelMap modeMape)
	{
	
		Page<MemberLeaveType> pageData = new Page<MemberLeaveType>();
		//给pageData设置参数
		WebUtils.setPageDataParameter(request, pageData);
		Compositor compositor = new Compositor("id",CompositorType.DESC);
		pageData.setCompositor(compositor);
		
		
		pageData = mbLeaveTypeService.find(pageData);		
	    modeMape.addAttribute("pageData", pageData);
	    
	    Pagination page = new Pagination();
		page.setIntTotalNum((int)pageData.getPagination().getTotalCount());
		page.setCurpage(pageData.getPagination().getPageNo());
		page.setPagenum(pageData.getPagination().getPageSize());
		modeMape.addAttribute("pagination", page.showPages());
	    
		return "/backstage/leaveMessage/leaveTypeData";
	}
	
	/**
	 * 删除新闻
	 * @param request
	 * @param modeMape
	 * @param id
	 * @return
	 */
	@RequestMapping("/backstage/deleteLeaveType")
	public String deleteType(HttpServletRequest request,ModelMap modeMape,Long leaveTypeId){		
		mbLeaveTypeService.delete(leaveTypeId);
		return "/backstage/leaveMessage/leaveTypeList";
	}
	
	
	/**
	 * 加载新增新闻页面
	 * @return
	 */
	@RequestMapping("/backstage/loadLeaveTypeAddPage")
	public String loadAddNoticePage(){
		return "/backstage/leaveMessage/addType";
		
	}
	
}
